package com.tange.ai.iot.client.gnssa.play

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import com.tange.ai.iot.client.gnssa.databinding.ActivityVideoChatRequestBinding
import com.tange.base.toolkit.onClicked
import com.tange.base.toolkit.paddingStatusBar

class ChatRequestActivity: AppCompatActivity() {

    companion object {
        private const val TAG = "ChatRequestActivity_"

        private const val PARAM_DEVICE_ID = "PARAM_DEVICE_ID"

        fun launch(context: Context, deviceId: String) {
            context.startActivity(Intent(context, ChatRequestActivity::class.java).apply {
                putExtra(PARAM_DEVICE_ID, deviceId)
                flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
            })
        }
    }

    private lateinit var binding: ActivityVideoChatRequestBinding

    private val mainHandler = Handler(Looper.getMainLooper())

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val deviceId = intent.getStringExtra(PARAM_DEVICE_ID)!!

        binding = ActivityVideoChatRequestBinding.inflate(layoutInflater).apply {
            setContentView(root)
            supportActionBar?.hide()
            root.paddingStatusBar()
        }

        com.tange.ai.iot.client.gnssa.utils.Utils.setStatusBar(this, Color.TRANSPARENT)

        binding.top.left.onClicked { finish() }


        binding.accept.onClicked {
            DeviceLiveActivity.launch(it.context, deviceId)
        }

        binding.reject.onClicked {
            finish()
        }

        binding.label.text = "$deviceId \n请求通话，是否接听？"


        mainHandler.postDelayed({}, 10 * 1000)
    }

    override fun onDestroy() {
        super.onDestroy()
        mainHandler.removeCallbacksAndMessages(null)
    }
}